<?php
class registerControl extends skymvc{
	
	public function __construct(){
		parent::__construct();	
	}
	
	public function onInit(){
		if(SHOPID){
			$this->gourl("/shopadmin.php?m=index");
		}
	}
	
	public function onDefault(){
		$this->smarty->display("register/index.html");
	}
	
	public function onsave(){
		$adminname=post('adminname','h');
		$password=post('password','h');
		$password2=post('password2','h');
		if(empty($adminname)){
			$this->goall("管理员名称不能为空",1);
		}
		if($password!=$password2){
			$this->goall("两次输入密码不一致",1);
		}
		if(M("shopadmin")->selectRow("adminname='".$adminname."'")){
			$this->goall("账号已经存在",1);
		}
		$salt=rand(1000,9999);
		$shopid=M("shop")->insert(array("dateline"=>time(),"shopname"=>$adminname));
		M("shop_data")->insert(array("shopid"=>$shopid));
		$data=array(
			"password"=>umd5($password.$salt),
			"salt"=>$salt,
			"adminname"=>$adminname,
			"shopid"=>$shopid,
		);
		M("shopadmin")->insert($data);
		$this->goall("注册成功");	
		
	}
}
?>